package cc.geguol.iodemo.randomaccessdemo;

import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.concurrent.CountDownLatch;

/**
 * 作者：13687
 * 日期：2017/6/18
 * 项目：IODemo
 * 描述：
 * 1. 需要一个raf 去写文件
 * 2. 需要一个输入流 去取文件
 * 3. 其实每个线程会对应一个输入流（因为输入流没法去指定文件指针）
 */
public class WriteAble extends BaseRunnable {

	private final InputStream in;
	private final RandomAccessFile af;

	public WriteAble(CountDownLatch countDownLatch, InputStream inputStream, RandomAccessFile accessFile) {
		super(countDownLatch);
		in = inputStream;
		af = accessFile;
	}

	@Override
	void verfery() throws IOException {
		byte[] buff = new byte[1024];
		int len = 0;
		while ((len = in.read(buff))!=-1){
			af.write(buff,0,buff.length);
		}

	}
}
